package dto;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import vo.messengerVO;
import db.MySql;

public class messengerDTO {

	private Connection conn = null;
	
	private messengerVO mvo = null;
	
	public messengerDTO() {
		this.conn = new MySql().getConn();
	}

	public void setVO(messengerVO mvo){
		this.mvo = mvo;
	}
	
	public boolean login_process(){
		boolean ensure_id = false;
		
		String sql = "select m_id, m_pw from semyadmin.messenger where m_id = ? and m_pw = ?"; 
		try {
			
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, mvo.getM_id());
			pst.setString(2, mvo.getM_pw());
			
			ResultSet rs = pst.executeQuery();
			
			while(rs.next()){
				ensure_id = true;
			}
			rs.close();
			pst.close();
			conn.close();
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		return ensure_id;
	}
	
	public boolean number_check(){
		boolean number_check = false;
		
		String sql = "select * "
				+ " from semyadmin.employees "
				+ " where e_number = ? "
				+  "and e_name ='0' ";
		try {
			
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setLong(1, mvo.getE_number());
			
			ResultSet rs = pst.executeQuery();
			
			while(rs.next()){
				number_check = true;
				System.out.println("실행 됨...");
			}
			rs.close();
			pst.close();
			conn.close();
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		return number_check;
	}
	
	public boolean id_check(){
		boolean id_check = false;
		
		String sql = "select m_id from semyadmin.messenger where m_id != ?"; 
		try {
			
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, mvo.getM_id());
			
			ResultSet rs = pst.executeQuery();
			
			while(rs.next()){
				id_check = true;
			}
			rs.close();
			pst.close();
			conn.close();
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		return id_check;
	}
}
